home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / tcl / tclx7.5a- / tclx7 / usr / local / bin / tclhelp < prev    next >
Encoding:
Tcl/Tk script  |  1995-11-14  |  9.7 KB  |  331 lines

  1. #!/usr/local/bin/wishx
  2.  
  3. # tclhelp.tcl --
  4. #
  5. # Tk program to access Extended Tcl & Tk help pages.  Uses internal functions
  6. # of TclX help command.
  7. #------------------------------------------------------------------------------
  8. # Copyright 1993-1995 Karl Lehenbauer and Mark Diekhans.
  9. #
  10. # Permission to use, copy, modify, and distribute this software and its
  11. # documentation for any purpose and without fee is hereby granted, provided
  12. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  13. # Mark Diekhans make no representations about the suitability of this
  14. # software for any purpose.  It is provided "as is" without express or
  15. # implied warranty.
  16. #------------------------------------------------------------------------------
  17. # $Id: tclhelp.tcl,v 5.0 1995/07/25 06:00:36 markd Rel $
  18. #------------------------------------------------------------------------------
  19.  
  20. #------------------------------------------------------------------------------
  21. # Add a button associated with either a file or directory in the help tree.
  22. # This handles creating frames to hold each row of buttons.  Buttons should
  23. # be delivered in accending row order, and accending column order within each
  24. # row.  Special handling is done for '..'/
  25.  
  26. proc AddButton {parent subject fileName row col} {
  27.  
  28.     # Prep name to use in button and other file info.
  29.  
  30.     set isDir [string match */ $fileName]
  31.     if [string match */ $subject] {
  32.         set subject [csubstr $subject 0 len-1]
  33.     }
  34.     if {$fileName == ".."} {
  35.         set fileName "<Up>"
  36.         set filePath [file dirname $subject]
  37.         set isDir 1
  38.     } else {
  39.         set filePath ${subject}/${fileName}
  40.     }
  41.  
  42.     # Set up a row frame, if needed.
  43.  
  44.     set nframe $parent.row$row
  45.     if {$col == 0} {
  46.         frame $nframe
  47.         pack $nframe -side top -expand 1 -anchor w -fill x
  48.     }
  49.  
  50.     # Set up the button.
  51.  
  52.     set buttonName $nframe.col$col
  53.     if $isDir {
  54.         button $buttonName -text $fileName -width 20 \
  55.             -command "DisplaySubject $filePath"
  56.     } else {
  57.         button $buttonName -text $fileName -width 20 \
  58.             -command "DisplayPage $filePath"
  59.     }
  60.     pack $buttonName -side left -anchor w
  61. }
  62.  
  63. #------------------------------------------------------------------------------
  64. # Create a frame to hold buttons for the specified list of either help files
  65. # or directories.
  66.  
  67. proc ButtonFrame {w title subject fileList} {
  68.     frame $w
  69.     label $w.label -relief flat -text $title -background SlateGray1
  70.     pack $w.label -side top -fill both
  71.     frame $w.buttons
  72.     pack $w.buttons -side top -expand 1 -anchor w
  73.     set col 0
  74.     set row 0
  75.     while {![lempty $fileList]} {
  76.         AddButton $w.buttons $subject [lvarpop fileList] $row $col
  77.         if {[incr col] >= 5} {
  78.             incr row
  79.             set col 0
  80.         }
  81.     }
  82. }
  83.  
  84. #------------------------------------------------------------------------------
  85. # Display the panels contain the subjects (directories) and the help files for
  86. # a given directory.
  87.  
  88. proc DisplaySubject {subject} {
  89.  
  90.     help:ListSubject $subject [help:ConvertPath $subject] subjects pages
  91.     if {$subject != "/"} {
  92.         lvarpush subjects ".."
  93.     }
  94.  
  95.     # Allow us to resize if the user has set the size.
  96.     wm geometry . ""
  97.  
  98.     set frame .tkhelp.pick
  99.     catch {destroy $frame}
  100.     frame $frame
  101.     pack $frame -side top -fill x
  102.     
  103.     ButtonFrame $frame.subjects "Subjects available in $subject" \
  104.         $subject $subjects
  105.     pack $frame.subjects -side top -fill x
  106.  
  107.     ButtonFrame $frame.pages "Help files available in $subject" \
  108.         $subject $pages
  109.     pack $frame.pages -side top -fill x
  110. }
  111.  
  112. #------------------------------------------------------------------------------
  113. # Display a file in a top-level text window.
  114.  
  115. proc DisplayPage {page} {
  116.     set fileName [file tail $page]
  117.  
  118.     set w ".tkhelp-[translit "." "_" $page]"
  119.  
  120.     if [winfo exists $w] {
  121.         destroy $w
  122.     }
  123.     toplevel $w
  124.  
  125.     wm title $w "Help on '$page'"
  126.     wm iconname $w "Help: $page"
  127.     wm minsize $w 1 1
  128.     frame $w.frame -borderwidth 10
  129.  
  130.     scrollbar $w.frame.yscroll -relief sunken \
  131.         -command "$w.frame.page yview"
  132.     text $w.frame.page -yscrollcommand "$w.frame.yscroll set" \
  133.         -width 80 -height 20 -relief sunken -wrap word
  134.     pack $w.frame.yscroll -side right -fill y
  135.     pack $w.frame.page -side top -expand 1 -fill both
  136.  
  137.     if [catch {
  138.             set contents [read_file [help:ConvertPath $page]]
  139.         } msg] {
  140.         set contents $msg
  141.     }
  142.     $w.frame.page insert 0.0 $contents
  143.     $w.frame.page configure -state disabled
  144.  
  145.     button $w.dismiss -text Dismiss -command "destroy $w"
  146.     pack $w.dismiss -side bottom -fill x
  147.     pack $w.frame -side top -fill both -expand 1
  148. }
  149.  
  150. #------------------------------------------------------------------------------
  151. # Set up the apropos panel.
  152.  
  153. proc AproposPanel {} {
  154.     global aproposEntryNumber aproposReferenceFrame referenceFrameItem
  155.  
  156.     set aproposEntryNumber 0
  157.  
  158.     if [winfo exists .apropos] {
  159.         destroy .apropos
  160.     }
  161.     toplevel .apropos
  162.     wm minsize .apropos 1 1
  163.  
  164.     # put in the dismiss button
  165.     set w .apropos.buttonFrame
  166.     frame $w
  167.     pack $w -side bottom -fill x
  168.     button $w.dismiss -text Dismiss -command "destroy .apropos"
  169.     pack $w.dismiss -side bottom -fill x
  170.  
  171.     frame .apropos.entryFrame
  172.     pack .apropos.entryFrame -side top -fill x
  173.  
  174.     label .apropos.entryFrame.label -text "Search for"
  175.     pack .apropos.entryFrame.label -side left
  176.  
  177.     entry .apropos.entryFrame.entry -relief sunken
  178.     pack .apropos.entryFrame.entry -side left -fill x -expand 1
  179.  
  180.     bind .apropos.entryFrame.entry <Return> PerformAproposSearch
  181.  
  182.     frame .apropos.canvasFrame
  183.     set w .apropos.canvasFrame
  184.  
  185.     canvas $w.canvas -yscrollcommand "$w.yscroll set" \
  186.             -xscrollcommand "$w.xscroll set" \
  187.             -width 15c -height 5c -relief sunken
  188.  
  189.     scrollbar $w.yscroll -relief sunken \
  190.         -command "$w.canvas yview"
  191.  
  192.     scrollbar $w.xscroll -relief sunken -orient horiz \
  193.         -command "$w.canvas xview"
  194.  
  195.     pack $w.xscroll -side bottom -fill x
  196.     pack $w.yscroll -side right -fill y
  197.     pack $w.canvas -in $w -expand yes -fill both
  198.     pack $w -side bottom -expand yes -fill both
  199.  
  200.     # Allow input without Button1 press.
  201.     focus .apropos.entryFrame.entry
  202.     update idletasks
  203. }
  204.  
  205. #---------------------------------------------------------------------------
  206. #put a line in the reference display for this apropos entry we've discovered
  207. #
  208. proc DisplayAproposReference {path description} {
  209.     global aproposEntryNumber aproposReferenceFrame
  210.  
  211.     set frame $aproposReferenceFrame.e$aproposEntryNumber
  212.     frame $frame
  213.     pack $frame -side top -anchor w
  214.  
  215.     button $frame.button -text $path -width 30 \
  216.         -command "DisplayPage /$path"
  217.     pack $frame.button -side left
  218.  
  219.     label $frame.label -text $description
  220.     pack $frame.label -side left
  221.  
  222.     incr aproposEntryNumber
  223. }
  224.  
  225. #---------------------------------------------------------------------------
  226. #the actual search is cadged from "apropos" in the tclx help system
  227. #
  228. proc PerformAproposSearch {} {
  229.     global TCLXENV referenceFrameItem aproposEntryNumber aproposReferenceFrame
  230.  
  231.     # Get expression, ignore if empty
  232.     set regexp [.apropos.entryFrame.entry get]
  233.     if ![clength $regexp] {
  234.         return
  235.     }
  236.  
  237.     #  start variables and clean up any residue from previous searches
  238.     set w .apropos.canvasFrame
  239.     set aproposEntryNumber 0
  240.     .apropos.canvasFrame.canvas delete all
  241.     set aproposReferenceFrame $w.canvas.frame
  242.     catch {destroy $aproposReferenceFrame}
  243.     catch {destroy .apropos.canvasFrame.failed}
  244.  
  245.     # create the frame we'll pack matches into and put it into the canvas
  246.     frame $aproposReferenceFrame
  247.     set referenceFrameItem \
  248.         [$w.canvas create window 2 2 -window $aproposReferenceFrame -anchor nw]
  249.  
  250.     set TCLXENV(help:lineCnt) 0
  251.  
  252.     # set up scan context
  253.     set ch [scancontext create]
  254.     scanmatch -nocase $ch $regexp {
  255.         set path [lindex $matchInfo(line) 0]
  256.         set desc [lrange $matchInfo(line) 1 end]
  257.         DisplayAproposReference $path $desc
  258.     }
  259.  
  260.     # perform search
  261.     foreach dir [help:RootDirs] {
  262.         foreach brief [glob -nocomplain $dir/*.brf] {
  263.             set briefFH [open $brief]
  264.             scanfile $ch $briefFH
  265.             close $briefFH
  266.         }
  267.     }
  268.  
  269.     # delete scan context
  270.     scancontext delete $ch
  271.  
  272.     # force display to update so we can find out our bounding box
  273.     update
  274.  
  275.     # if nothing matched, complain
  276.     if {$aproposEntryNumber == 0} {
  277.         label $aproposReferenceFrame.failed -text "NOTHING MATCHED."
  278.         pack $aproposReferenceFrame.failed -side left
  279.     }
  280.  
  281.     # set the canvas scrollregion to the size of the bounding box
  282.     lassign [.apropos.canvasFrame.canvas bbox $referenceFrameItem] \
  283.         dummy dummy xSize ySize
  284.     .apropos.canvasFrame.canvas configure -scrollregion \
  285.     "0 0 $xSize $ySize"
  286. }
  287.  
  288. #------------------------------------------------------------------------------
  289. # Set up the command buttons.
  290.  
  291. proc CreateCommandButtons {frameName} {
  292.     frame $frameName
  293.  
  294.     button $frameName.quit -text "Quit" -command exit
  295.     pack $frameName.quit -side left
  296.  
  297.     button $frameName.apropos -text "Apropos" -command AproposPanel
  298.     pack $frameName.apropos -side left
  299. }
  300.  
  301. #------------------------------------------------------------------------------
  302. # Tk base help command for Tcl/Tk/TclX.  Directories in args are pushed on the
  303. # path so that they are included in help search.
  304.  
  305. proc tkhelp addPaths {
  306.     global auto_path
  307.     if ![auto_load help] {
  308.         puts stderr "couldn't auto_load TclX 'help' command"
  309.         exit 255
  310.     }
  311.     foreach dir $addPaths {
  312.         lvarpush auto_path $dir
  313.     }
  314.     CreateCommandButtons .command
  315.     pack .command -side top -fill x
  316.  
  317.     frame .tkhelp
  318.     pack .tkhelp -side top -fill both
  319.  
  320.     DisplaySubject "/"
  321.  
  322. }
  323.  
  324. if [catch {
  325.     tkhelp $argv
  326. } msg] {
  327.     tkerror $msg
  328. }
  329.  
  330.